import axios from "axios"
import { RootAction, TodoAction } from ".."

export const delTodo = (id: number) : TodoAction => {
    return {
        type:'todos/del',
        payload: id
    }
}

export const addTodo = (name: string): TodoAction => {
    return {
        type: "todos/add",
        name 
    }
}

export const updateTodo = (id: number): TodoAction => {
    return {
        type:"todos/update",
        id 
    }
}


export const getTodos = () : RootAction => {
    return  async dispatch => {
        // 发请求
        const res = await axios.get('https://www.fastmock.site/mock/37d3b9f13a48d528a9339fbed1b81bd5/book/api/todos')
        console.log(res)

        dispatch({
            type:'todos/init',
            playload: res.data.data
        })
    }
}
